from flask import Blueprint, request

from model.Food import Food
from service.food_service import FoodService
from utils.ResultUtil import Response
from model.User import User
food = Blueprint("food", __name__, url_prefix="/food")


@food.route('/list', methods=['GET'])
def user_list():
    return Response().success(FoodService().list())

@food.route('/queryMenu', methods=['GET'])
def queryMenu():
    id = request.args.get("id")
    query = request.args.get("query")

    return Response().success(FoodService().queryFoodByHollId(id, query))

@food.route('/detail', methods=['GET'])
def detail():
    id = request.args.get("id")
    return Response().success(FoodService().getDetail(id))

@food.route('/putImg',methods=['POST'])
def putImg():
    data = request.get_json()
    return Response().success(FoodService().putFoodImg(data["img"]))

@food.route('/getType', methods=['GET'])
def getTypes():
    return Response().success(FoodService().getFoodType())

@food.route('/getDingHall', methods=['GET'])
def getType():
    return Response().success(FoodService().getDingHall())

@food.route('/addFood', methods=['POST'])
def addFood():
    data = request.get_json()
    return Response().success(FoodService().addFood(Food.decode(data)))

@food.route('/deleteById', methods=['GET'])
def delete():
    id = request.args.get("id")
    return Response().success(FoodService().deleteFood(id))

@food.route('/update',methods=['POST'])
def updateFood():
    data = request.get_json()
    id = request.get_json()["id"]
    return Response().success(FoodService().updateFood(Food.decode(data),id))

@food.route('/getByAuthorId',methods=['GET'])
def selectByAuthorId():
    id = request.args.get("authorId")
    return Response().success(FoodService().selectByAuthorId(id))